<?php

namespace app\api\controller;


use app\common\service\UserToken;

class Login extends ApiBase {
    public function getToken() {
        if (request()->isPost()) {
            $code         = input('post.code');
            $tokenService = new UserToken();
            $token        = $tokenService->getToken($code);
            $result       = [
                'token'     => $token,
                'expert_in' => time() + config('setting.token_expire_in')
            ];
            return show(0, '登录成功', $result);
        } else {
            return show(1, '请求异常');
        }
    }

    public function putUserInfo() {
        if (request()->isPost()) {
            $data         = input('post.');
            $tokenService = new UserToken();
            $tokenService->putUserInfo($data);
            return show(0, '保存用户数据成功');
        } else {
            return show(1, '请求异常');
        }
    }
}